library ieee;
use ieee.std_logic_1164.all;

entity Electronic_keyboard is
port (clk:in std_logic;
	play:in std_logic;
	EN:in std_logic;--0:Elc_keyboard;
	key:in integer range 0 to 16;
	note_code:OUT integer range 0 to 31
	);
end entity;

architecture Elc_keyBoard of Electronic_keyboard is

begin
process(key,play,EN,clk)
variable sign :integer range 0 to 2:=0;
begin
if play='0' and EN='0' then
	if(rising_edge(clk))then
		if key=12 then
			sign:=0;--mid
		elsif key=16 then
			sign:=1;--low
		elsif key=8 then
			sign:=2;--high
		end if;
		if key>=1 and key<=7 then--1~7
			note_code<=key+10*sign;
		else
			note_code<=0;--stop
		end if;
	end if;
else
	note_code<=0;
	sign:=0;
end if;
end process;
	

end Elc_keyBoard; 